package io.renren.modules.department.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.department.entity.DepartmentInforEntity;
import io.renren.modules.department.service.DepartmentInforService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 部门信息表
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2021-12-31 10:59:45
 */
@RestController
@RequestMapping("department/departmentinfor")
public class DepartmentInforController {
    @Autowired
    private DepartmentInforService departmentInforService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("department:departmentinfor:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = departmentInforService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{departmentId}")
    @RequiresPermissions("department:departmentinfor:info")
    public R info(@PathVariable("departmentId") Long departmentId){
        DepartmentInforEntity departmentInfor = departmentInforService.getById(departmentId);

        return R.ok().put("departmentInfor", departmentInfor);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("department:departmentinfor:save")
    public R save(@RequestBody DepartmentInforEntity departmentInfor){
        departmentInforService.save(departmentInfor);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("department:departmentinfor:update")
    public R update(@RequestBody DepartmentInforEntity departmentInfor){
        ValidatorUtils.validateEntity(departmentInfor);
        departmentInforService.updateById(departmentInfor);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("department:departmentinfor:delete")
    public R delete(@RequestBody Long[] departmentIds){
        departmentInforService.removeByIds(Arrays.asList(departmentIds));

        return R.ok();
    }

}
